<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%@include file="/commons/taglibs.jsp" %>
<!DOCTYPE html>
<html>
<fmt:bundle basename="res">
<head>
    <meta charset="utf-8">
    <title><fmt:message key='lb'/></title>
    <jsp:include page="/WEB-INF/commons/commons-header.jsp" flush="true"/>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">

            <div class="layui-form-item">
                <form name="totalForm" id="totalForm" action="${web_domain}/securitys/page/" method="get">

                    <div class="layui-inline">
                        <label class="layui-form-label"><fmt:message key='ymmc'/></label>
                        <div class="layui-input-inline">
                            <input type="text" name="name" value="${params.name}" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <button class="layui-btn layui-btn-sm layuiadmin-btn-list" id="search"><i class="layui-icon layui-icon-search layuiadmin-button-btn"></i> <fmt:message key='ss'/></button>
                    </div>
                </form>
            </div>
        </div>

    </div>

    <div class="layui-card">
        <div class="layui-field-box layui-form">
            <shiro:hasPermission name="users:create">
                <a href="javascript:void(0);" class="layui-btn layui-btn-sm layui-btn-normal" id="add"><i class="layui-icon">&#xe61f;</i> <fmt:message key='tj'/></a>
            </shiro:hasPermission>

            <table class="layui-table" lay-size="sm">
                <thead>
                <th><fmt:message key='xh'/></th>
                <th><fmt:message key='ymmc'/></th>
                <th><fmt:message key='ymxdydz'/></th>
                <th><fmt:message key='xk'/></th>
                <th><fmt:message key='cz'/></th>
                </thead>
                <tbody>

                <c:forEach items="${page.result }" var="item" varStatus="status">
                    <tr>
                        <td>${status.index+1 }</td>
                        <td>${item.name }</td>
                        <td>${item.href }</td>
                        <td>
                            <c:forEach items="${item.permissions}" var="permission">
                                <span class="layui-badge layui-bg-cyan">${permission.name}  ${permission.permission}</span>
                            </c:forEach>
                        </td>
                        <td>
                            <div class="layui-btn-container">
                                <a href="javascript:void(0);" data-url="${web_domain}/securitys/page/${item.id}/edit" class="layui-btn layui-btn-xs feijin-modify"><fmt:message key='bj'/></a>
                                <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-danger layui-btn-xs feijin-remove"><fmt:message key='sc'/></a>
                            </div>
                        </td>
                    </tr>
                </c:forEach>
                </tbody>
            </table>
            <jsp:include page="/commons/page.jsp" flush="true"/>
        </div>
    </div>

</div>

<script>

    $(function () {

        //添加页面
        $("#add").click(function () {
            layer.open({
                type: 2
                , title: '<fmt:message key='tjym'/>'
                , content: '${web_domain}/securitys/page/create'
                , maxmin: true
                , area: ['80%', '90%']
                , btn: ['<fmt:message key='qd1'/>', '<fmt:message key='qx'/>']
                , yes: function (index, layero) {
                    var submit = layero.find('iframe').contents().find("#submit");
                    submit.click();
                }
            });
        });

        //编辑页面
        $(".feijin-modify").click(function () {

            var url = $(this).attr("data-url");

            layer.open({
                type: 2
                , title: '<fmt:message key='bjym'/>'
                , content: url
                , maxmin: true
                , area: ['80%', '90%']
                , btn: ['<fmt:message key='qd1'/>', '<fmt:message key='qx'/>']
                , yes: function (index, layero) {
                    var submit = layero.find('iframe').contents().find("#submit");
                    submit.click();
                }
            });
        });

        //删除页面
        $(".feijin-remove").click(function () {
            var id = $(this).attr("data-id");
            layui.use('layer', function () {
                var layer = layui.layer;
                layer.open({
                    type: 0,
                    title: '<fmt:message key='scym'/>',//自定义标题样式
                    border: [0],
                    content: '<span class="orange"><fmt:message key='sccz,qdscgymm'/></span>',
                    btn: ['<fmt:message key='sc'/>', '<fmt:message key='qx'/>'],
                    yes: function () {
                        $.ajax({
                            type: "post",
                            url: "${web_domain}/securitys/page/remove",
                            dataType: "json",
                            data: {
                                "id": id,
                                "_method": "delete"
                            },
                            success: function (data) {
                                if (data.status) {
                                    location.reload();
                                } else {
                                    alert(data.message);
                                }
                            }
                        });
                    },
                    no: function () {
                        layer.close(index);
                    }
                });
            });
        });
    });
</script>
</body>
</fmt:bundle>
</html>
